package ynu.edu.dish.config;

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web配置类
 */
@Configuration
@RequiredArgsConstructor
public class WebConfig implements WebMvcConfigurer {

    private final JwtInterceptor jwtInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加JWT拦截器，拦截需要认证的请求
        registry.addInterceptor(jwtInterceptor)
                .addPathPatterns("/dishes/**", "/dish-categories/**")
                .excludePathPatterns(
                        // 公开接口，不需要认证
                        "/dishes/list/**",
                        "/dishes/category/**",
                        "/dishes/merchant/**",
                        "/dishes/search/**",
                        "/dishes/recommended/**",
                        "/dishes/special/**",
                        "/dish-categories/list/**",
                        "/dish-categories/merchant/**",
                        "/internal/**"  // 排除内部API路径，不需要JWT认证
                );
    }
} 